<?php

namespace app\admin\model;

use app\admin\model\Image;

class Villageimages extends Base
{

    // 数据表名称
    //protected $table;

    // 当前模型名称 不带前缀
    protected $name = 'villageimages';

    // 数据表主键 复合主键使用数组定义 不设置则自动获取
    protected $pk = 'id';


    public static function _after_insert($data){
        /*if(isset($data['imgIds']) && !empty($data['imgIds'])){
            if(is_array($data['imgIds'])){
                foreach ($data['imgIds'] as $item) {
                    Image::where('id', $item)->update(['relatedId' => $data['id'], 'relatedTable' => 'Villageimages']);
                }
            }
        }*/
        if(isset($data['imgId']) && !empty($data['imgId'])){
            Image::where('id', $data['imgId'])->update(['relatedId' => $data['id'], 'relatedTable' => 'Villageimages']);
        }
    }

    public static function _after_delete($id){
        if(is_array($id)){
            Image::where('relatedTable', 'Villageimages')->whereIn('relatedId', $id)->delete();
        }else{
            Image::where('relatedTable', 'Villageimages')->where('relatedId', $id)->delete();
        }
    }

}